package cn.gaozhong.system.controller;


import cn.gaozhong.basic.util.AjaxResult;
import cn.gaozhong.basic.util.PageList;
import cn.gaozhong.system.domain.SystemDictionaryType;
import cn.gaozhong.system.query.SystemDictionaryTypeQuery;
import cn.gaozhong.system.service.ISystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system")
public class SystemDictionaryTypeController {
    @Autowired
    private ISystemDictionaryTypeService systemDictionaryTypeService;

    @GetMapping("/{id}")
    public SystemDictionaryType queryById(@PathVariable("id") Long id){
        return systemDictionaryTypeService.queryById(id);
    }

    @GetMapping
    public List<SystemDictionaryType> queryAll(){
        return systemDictionaryTypeService.queryAll();
    }
    @PostMapping
    public PageList<SystemDictionaryType> queryPage(@RequestBody SystemDictionaryTypeQuery query){
        return systemDictionaryTypeService.queryPage(query);
    }
    @PutMapping
    public AjaxResult addOrUpd(@RequestBody SystemDictionaryType systemDictionaryType){
        try {
            if (systemDictionaryType.getId()==null){
                systemDictionaryTypeService.save(systemDictionaryType);
            } else {
                systemDictionaryTypeService.update(systemDictionaryType);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试");
        }
    }
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            systemDictionaryTypeService.removeById(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试");
        }
    }
    @PatchMapping
    public AjaxResult batchRemove(@RequestBody List<Long> ids){
        try {
            systemDictionaryTypeService.patchRemove(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试");
        }
    }
   /* @GetMapping("/tree")
    public List<SystemDictionaryType> queryTree(){
        return systemDictionaryTypeService.queryTree();
    }*/
}
